﻿using UnityEngine;
using System.Collections;

public class RoopBackground : MonoBehaviour
{
    Transform bg01, bg02;
    float width;
    Transform first, second;
    private void Awake()
    {
        bg01 = transform.GetChild(0);
        bg02 = transform.GetChild(1);
        width = bg01.GetComponent<SpriteRenderer>().sprite.bounds.size.x;
        bg02.position = bg01.position + new Vector3(width, 0f);
    }
    private void Update()
    {
        if (bg02.transform.position.x + width / 2f - CameraController.Instance.XRightEdge < 0.5f)
        {
            bg01.position = bg02.position + new Vector3(width, 0f);
            Transform temp = bg01;
            bg01 = bg02;
            bg02 = temp;
        }
    }
}
